﻿using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Treeview.Model
{
    public class MyMenuItem : ObservableObject
    {
        public MyMenuItem(string Text)
        {
            this.Text = Text;
            this.Childs = new ObservableCollection<MyMenuItem>();
        }
        public MyMenuItem()
        {
            this.Childs = new ObservableCollection<MyMenuItem>();
        }

        private string text;
        public string Text
        {
            get
            {
                return text;
            }
            set
            {
                text = value;
                RaisePropertyChanged();
            }
        }

        private ObservableCollection<MyMenuItem> childs;
        public ObservableCollection<MyMenuItem> Childs
        {
            get
            {
                return childs;
            }
            set
            {
                childs = value;
                RaisePropertyChanged();
            }
        }



    }


    public static class MyMenuItemExtension
    {
        internal static MyMenuItem Search(
this MyMenuItem node,
Predicate<MyMenuItem> match)
        {

            Queue<MyMenuItem> queue = new Queue<MyMenuItem>();
            queue.Enqueue(node);
            while (queue.Count > 0)
            {
                MyMenuItem thisNode = queue.Dequeue();
                if (match(thisNode))
                    return thisNode;
                foreach (MyMenuItem child in thisNode.Childs)
                    queue.Enqueue(child);
            }
            return null;
        }
    }

}
